package xyf.p02.stack_queue;

import java.util.Stack;

/**
 * ClassName: P0739_DailyTemperatures
 * Description:
 * Author: xyf
 * Date: 9/7/22 7:47 PM
 * Version: 1.0
 **/
public class P0739_DailyTemperatures
{
    private Stack<Integer> stack = new Stack<>();

    public int[] dailyTemperatures(int[] temperatures)
    {
        int[] res = new int[temperatures.length];
        for (int i = 0; i < temperatures.length; i++)
        {
            while (!stack.isEmpty() && temperatures[stack.peek()] < temperatures[i])
            {
                Integer index = stack.pop();
                res[index] = i - index;
            }

            stack.push(i);
        }

        while (!stack.isEmpty())
        {
            Integer index = stack.pop();
            res[index] = 0;
        }
        return res;
    }
}